package cn.tedu.lbs.basic.web.controller;

import cn.tedu.lbs.basic.web.service.LoginService;
import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.pojo.passport.param.AdminLoginParam;
import com.tarena.lbs.pojo.passport.param.UserLoginParam;
import com.tarena.lbs.pojo.passport.vo.LoginVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class LoginController {
    //调用登录的业务代码
    @Autowired
    private LoginService loginService;
    //参考笔记中提前接口文档 编写
    @PostMapping("/passport/admin/login")
    public Result<LoginVO> adminlogin(AdminLoginParam param) throws BusinessException {
        log.info("后台用户登录,入参:{}",param);
        Thread thread = Thread.currentThread();
        log.info("登录控制层 执行线程对象:{},id:{}",thread,thread.getId());
        //整个项目 控制层 几乎没有复杂逻辑.逻辑都在业务层
        //1.如果Result有泛型 有对象 说明data属性要携带数据返回 控制层要什么 业务层就给什么
        LoginVO vo=loginService.doAdminLogin(param);
        //2.如果Result没有数据 泛型Void 说明data数据是空
        log.info("后台用户登录,入参:{},出参:{}",param,vo);
        return new Result<>(vo);
    }

    @PostMapping("/passport/user/login")
    public Result<LoginVO> userLogin(UserLoginParam userLoginParam)
        throws BusinessException{
        return new Result<>(loginService.doUserLogin(userLoginParam));
    }

}
